<?php
/*
Module Group: news
Module Group Name: 图文
Description: 这是一个用来处理图文信息的插件
Version: 1.0
Display: 0
Iconurl: http://www.happyidea.com.cn/resource/wx_icon/news.png
Author: lr
Modules: news
*/
class newsModule extends Module {
	
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp ( 'news', 'news' );
	}
	
	/*
	 * 激活创建数据库
	*/
	public function activate() {
	}
	
	public function run($message, $material, $userStatus) {
		Log::write('Enter function newsModule');
		
		$materialObj = simplexml_load_string($material->xml,
				'SimpleXMLElement', LIBXML_NOCDATA);
		
		$rm = $message->reply(message_type_news);
		
		$customerId = Session::$user['customerId'];
		$articles = array();
		$articlesXml = $materialObj->Articles;
		foreach ($articlesXml->item as $item) {
			$item->url = get_session_url($item->url, $customerId, $message->fromUserName);;
			array_push($articles, $item);
		}
		$rm->articles = $articles;
		if(!empty($material->accessTag) && !empty($message->fromUserName)){	
			 setAccessTags($material->accessTag,$message->fromUserName,module_handle_news, $message->id);
		}
		return $rm;
	}

	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		switch ($method) {
			case 'getNewsMaterialFromURL':
				news::getNewsMaterialFromURL($param->url);
				break;
		}
	}
	
}

$module = new newsModule();
Module::addModule($module);